package org.example.web3j.controller;

import org.example.web3j.entity.response.ResponseDTO;
import org.example.web3j.service.Web3jExampleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.concurrent.CompletableFuture;

@RestController
@RequestMapping("/api/blockchain")
public class BlockchainController {

    @Autowired
    private Web3jExampleService blockchainService;

    // 创建新钱包
//    @PostMapping("/wallet")
//    public String createWallet(@RequestParam String password) throws Exception {
//        return blockchainService.createWallet(password);
//    }

    // 查询余额
    @GetMapping("/balance/{address}")
    public ResponseDTO getBalance(@PathVariable String address) throws Exception {
        BigDecimal balance = blockchainService.getBalance(address);
        ResponseDTO responseDTO = new ResponseDTO();
        responseDTO.setData(balance.toString());
        return responseDTO;
    }

    // 发送交易
//    @PostMapping("/transaction")
//    public String sendTransaction(@RequestBody TransactionRequest request) throws Exception {
//        return blockchainService.sendTransaction(
//                request.getWalletPath(),
//                request.getPassword(),
//                request.getToAddress(),
//                request.getAmount()
//        );
//    }

    // 异步发送交易
//    @PostMapping("/transaction/async")
//    public CompletableFuture<String> sendTransactionAsync(@RequestBody TransactionRequest request) throws Exception {
//        return blockchainService.sendTransactionAsync(
//                request.getWalletPath(),
//                request.getPassword(),
//                request.getToAddress(),
//                request.getAmount()
//        );
//    }
}    